package com.zmj.sy.mom.srv.aps.controller;


import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseIdsReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.plate.*;
import com.zmj.sy.mom.srv.aps.config.AspectLog;
import com.zmj.sy.mom.srv.aps.feign.ApsMesFeign;
import com.zmj.sy.mom.srv.aps.lock.BaseRepeatLock;
import com.zmj.sy.mom.srv.aps.service.PickService;
import com.zmj.sy.mom.srv.aps.service.PlateService;
import com.zmj.sy.mom.srv.aps.utils.SyExceptionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Api(tags = "钢板")
@RestController
@RequestMapping("/plate")
public class PlateController {

    private final PlateService plateService;
    private final PickService pickService;
    private final ApsMesFeign apsMesFeign;

    @ApiOperation("钢板待领料列表")
    @GetMapping("/list")
    public BasePageResVo<PlatePickListResVo> pickList(PlatePickListReqVo reqVo){
        return plateService.pickList(reqVo);
    }

    @Deprecated
    @ApiOperation("钢板领料")
    @PostMapping("/pick")
    public BaseResVo pick(BaseIdsReqVo reqVo){
        if(5>3){
            throw SyExceptionUtils.e("该功能已废弃,请从板材领料处进行领料单下发!");
        }
        plateService.pick(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("钢板打包-定时")
    @PostMapping("/pickJob")
    public BaseResVo pickJob(){
        plateService.pickJob();
        return BaseResVo.ok();
    }

    @ApiOperation("出库")
    @PostMapping("/outbound")
    @AspectLog(apiName = "钢板出库", operationType = 4)
    @BaseRepeatLock(lockKey = "#reqVo.materCode", lockTime = 10)
    public BaseResVo outbound(PlateOutboundReqVo reqVo){
        plateService.outbound(reqVo);

        try {
            // 通知普达进行解析
            pickService.plateSendPd( null, reqVo.getMaterCode());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return BaseResVo.ok();
    }
    @ApiOperation("生成预处理任务")
    @GetMapping("/makeYcl")
    public BaseResVo outbound(String reqVo){
        plateService.makeYcl(reqVo);
        return BaseResVo.ok();
    }

    @ApiOperation("撤消出库")
    @PostMapping("/unOutbound")
    @AspectLog(apiName = "撤消出库", operationType = 4)
    public BaseResVo unOutbound(List<String> materialIds){
        plateService.unOutbound(materialIds);
        return BaseResVo.ok();
    }

    @ApiOperation("零件列表")
    @GetMapping("/partList")
    public BaseListResVo<PlatePartListResVo> partList(PlatePartListReqVo reqVo){
        return plateService.partList(reqVo);
    }

    @ApiOperation("解锁")
    @PostMapping("/updateNxolpstatus")
    @AspectLog(apiName = "解锁", operationType = 4)
    public BaseResVo updateNxolpstatus(@RequestBody UpdateNxolpstatusVo dto){
        plateService.plateLock(dto);
        apsMesFeign.updateNxolpstatus(dto);
        return BaseResVo.ok();
    }
}
